package org.scboy.dbms.controller;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.dbms.service.SqlEntityService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/base/sqlentity")
@Menu("微服务管理系统.SQL配置管理")
public class SqlEntityController {

	@Autowired
	SqlEntityService service;
	
	@PostMapping("page")
	@Permission("分页查询")
	public Result page(@RequestBody Model params){
		Page page=service.page(params);
		return Result.Success(page);	
	}
	
	@PostMapping("add")
	@Permission("新增sql配置")
	public Result add(@RequestBody Model params){
		if(service.add(params)){
			return Result.Success("SQL_ENTITY_ADD_SUCCESS");
		}else{
			return Result.Error("SQL_ENTITY_ADD_ERROR");
		}
	}
	
	
	@GetMapping("get")
	@Permission("获取sql配置详情")
	public Result get(String id){
		return Result.Success(service.get(id));
	}
	
	@PutMapping("update")
	@Permission("更新sql配置")
	public Result update(@RequestBody Model params){
		if(service.update(params)){
			return Result.Success("SQL_ENTITY_UPDATE_SUCCESS");
		}else{
			return Result.Error("SQL_ENTITY_UPDATE_ERROR");
		}		
	}

	@DeleteMapping("delete")
	@Permission("删除sql配置")
	public Result delete(String id){
		if(service.delete(id)){
			return Result.Success("SQL_ENTITY_DELETE_SUCCESS");
		}else{
			return Result.Error("SQL_ENTITY_DELETE_ERROR");
		}
	}
	
}
